{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "440d361e-f41e-494a-98a3-aa87cf0087af",
   "metadata": {
    "ExecuteTime": {
     "start_time": "2023-12-18T21:24:20.798698Z",
     "end_time": "2023-12-18T21:24:21.110711Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import ssl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "ename": "HTTPError",
     "evalue": "HTTP Error 404: Not Found",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mHTTPError\u001B[0m                                 Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[6], line 10\u001B[0m\n\u001B[0;32m      8\u001B[0m url \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m'\u001B[39m\u001B[38;5;124mhttps://finance.yahoo.com/quote/COST/history?p=COST&guccounter=1\u001B[39m\u001B[38;5;124m'\u001B[39m\n\u001B[0;32m      9\u001B[0m \u001B[38;5;66;03m#读取网页数据\u001B[39;00m\n\u001B[1;32m---> 10\u001B[0m dfs \u001B[38;5;241m=\u001B[39m \u001B[43mpd\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mread_html\u001B[49m\u001B[43m(\u001B[49m\u001B[43murl\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32mC:\\Python310\\lib\\site-packages\\pandas\\io\\html.py:1245\u001B[0m, in \u001B[0;36mread_html\u001B[1;34m(io, match, flavor, header, index_col, skiprows, attrs, parse_dates, thousands, encoding, decimal, converters, na_values, keep_default_na, displayed_only, extract_links, dtype_backend, storage_options)\u001B[0m\n\u001B[0;32m   1229\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(io, \u001B[38;5;28mstr\u001B[39m) \u001B[38;5;129;01mand\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28many\u001B[39m(\n\u001B[0;32m   1230\u001B[0m     [\n\u001B[0;32m   1231\u001B[0m         is_file_like(io),\n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m   1235\u001B[0m     ]\n\u001B[0;32m   1236\u001B[0m ):\n\u001B[0;32m   1237\u001B[0m     warnings\u001B[38;5;241m.\u001B[39mwarn(\n\u001B[0;32m   1238\u001B[0m         \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mPassing literal html to \u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mread_html\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m is deprecated and \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m   1239\u001B[0m         \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mwill be removed in a future version. To read from a \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m   1242\u001B[0m         stacklevel\u001B[38;5;241m=\u001B[39mfind_stack_level(),\n\u001B[0;32m   1243\u001B[0m     )\n\u001B[1;32m-> 1245\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43m_parse\u001B[49m\u001B[43m(\u001B[49m\n\u001B[0;32m   1246\u001B[0m \u001B[43m    \u001B[49m\u001B[43mflavor\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mflavor\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1247\u001B[0m \u001B[43m    \u001B[49m\u001B[43mio\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mio\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1248\u001B[0m \u001B[43m    \u001B[49m\u001B[43mmatch\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mmatch\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1249\u001B[0m \u001B[43m    \u001B[49m\u001B[43mheader\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mheader\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1250\u001B[0m \u001B[43m    \u001B[49m\u001B[43mindex_col\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mindex_col\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1251\u001B[0m \u001B[43m    \u001B[49m\u001B[43mskiprows\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mskiprows\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1252\u001B[0m \u001B[43m    \u001B[49m\u001B[43mparse_dates\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mparse_dates\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1253\u001B[0m \u001B[43m    \u001B[49m\u001B[43mthousands\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mthousands\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1254\u001B[0m \u001B[43m    \u001B[49m\u001B[43mattrs\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mattrs\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1255\u001B[0m \u001B[43m    \u001B[49m\u001B[43mencoding\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mencoding\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1256\u001B[0m \u001B[43m    \u001B[49m\u001B[43mdecimal\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mdecimal\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1257\u001B[0m \u001B[43m    \u001B[49m\u001B[43mconverters\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mconverters\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1258\u001B[0m \u001B[43m    \u001B[49m\u001B[43mna_values\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mna_values\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1259\u001B[0m \u001B[43m    \u001B[49m\u001B[43mkeep_default_na\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mkeep_default_na\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1260\u001B[0m \u001B[43m    \u001B[49m\u001B[43mdisplayed_only\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mdisplayed_only\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1261\u001B[0m \u001B[43m    \u001B[49m\u001B[43mextract_links\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mextract_links\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1262\u001B[0m \u001B[43m    \u001B[49m\u001B[43mdtype_backend\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mdtype_backend\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1263\u001B[0m \u001B[43m    \u001B[49m\u001B[43mstorage_options\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mstorage_options\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m   1264\u001B[0m \u001B[43m\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32mC:\\Python310\\lib\\site-packages\\pandas\\io\\html.py:988\u001B[0m, in \u001B[0;36m_parse\u001B[1;34m(flavor, io, match, attrs, encoding, displayed_only, extract_links, storage_options, **kwargs)\u001B[0m\n\u001B[0;32m    977\u001B[0m p \u001B[38;5;241m=\u001B[39m parser(\n\u001B[0;32m    978\u001B[0m     io,\n\u001B[0;32m    979\u001B[0m     compiled_match,\n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m    984\u001B[0m     storage_options,\n\u001B[0;32m    985\u001B[0m )\n\u001B[0;32m    987\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m--> 988\u001B[0m     tables \u001B[38;5;241m=\u001B[39m \u001B[43mp\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mparse_tables\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    989\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mValueError\u001B[39;00m \u001B[38;5;28;01mas\u001B[39;00m caught:\n\u001B[0;32m    990\u001B[0m     \u001B[38;5;66;03m# if `io` is an io-like object, check if it's seekable\u001B[39;00m\n\u001B[0;32m    991\u001B[0m     \u001B[38;5;66;03m# and try to rewind it before trying the next parser\u001B[39;00m\n\u001B[0;32m    992\u001B[0m     \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mhasattr\u001B[39m(io, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mseekable\u001B[39m\u001B[38;5;124m\"\u001B[39m) \u001B[38;5;129;01mand\u001B[39;00m io\u001B[38;5;241m.\u001B[39mseekable():\n",
      "File \u001B[1;32mC:\\Python310\\lib\\site-packages\\pandas\\io\\html.py:248\u001B[0m, in \u001B[0;36m_HtmlFrameParser.parse_tables\u001B[1;34m(self)\u001B[0m\n\u001B[0;32m    240\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mparse_tables\u001B[39m(\u001B[38;5;28mself\u001B[39m):\n\u001B[0;32m    241\u001B[0m \u001B[38;5;250m    \u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[0;32m    242\u001B[0m \u001B[38;5;124;03m    Parse and return all tables from the DOM.\u001B[39;00m\n\u001B[0;32m    243\u001B[0m \n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m    246\u001B[0m \u001B[38;5;124;03m    list of parsed (header, body, footer) tuples from tables.\u001B[39;00m\n\u001B[0;32m    247\u001B[0m \u001B[38;5;124;03m    \"\"\"\u001B[39;00m\n\u001B[1;32m--> 248\u001B[0m     tables \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_parse_tables(\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_build_doc\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m, \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mmatch, \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mattrs)\n\u001B[0;32m    249\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m (\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_parse_thead_tbody_tfoot(table) \u001B[38;5;28;01mfor\u001B[39;00m table \u001B[38;5;129;01min\u001B[39;00m tables)\n",
      "File \u001B[1;32mC:\\Python310\\lib\\site-packages\\pandas\\io\\html.py:811\u001B[0m, in \u001B[0;36m_LxmlFrameParser._build_doc\u001B[1;34m(self)\u001B[0m\n\u001B[0;32m    809\u001B[0m             \u001B[38;5;28;01mpass\u001B[39;00m\n\u001B[0;32m    810\u001B[0m     \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m--> 811\u001B[0m         \u001B[38;5;28;01mraise\u001B[39;00m e\n\u001B[0;32m    812\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[0;32m    813\u001B[0m     \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28mhasattr\u001B[39m(r, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mtext_content\u001B[39m\u001B[38;5;124m\"\u001B[39m):\n",
      "File \u001B[1;32mC:\\Python310\\lib\\site-packages\\pandas\\io\\html.py:790\u001B[0m, in \u001B[0;36m_LxmlFrameParser._build_doc\u001B[1;34m(self)\u001B[0m\n\u001B[0;32m    788\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[0;32m    789\u001B[0m     \u001B[38;5;28;01mif\u001B[39;00m is_url(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mio):\n\u001B[1;32m--> 790\u001B[0m         \u001B[38;5;28;01mwith\u001B[39;00m \u001B[43mget_handle\u001B[49m\u001B[43m(\u001B[49m\n\u001B[0;32m    791\u001B[0m \u001B[43m            \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mio\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mr\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mstorage_options\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mstorage_options\u001B[49m\n\u001B[0;32m    792\u001B[0m \u001B[43m        \u001B[49m\u001B[43m)\u001B[49m \u001B[38;5;28;01mas\u001B[39;00m f:\n\u001B[0;32m    793\u001B[0m             r \u001B[38;5;241m=\u001B[39m parse(f\u001B[38;5;241m.\u001B[39mhandle, parser\u001B[38;5;241m=\u001B[39mparser)\n\u001B[0;32m    794\u001B[0m     \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[0;32m    795\u001B[0m         \u001B[38;5;66;03m# try to parse the input in the simplest way\u001B[39;00m\n",
      "File \u001B[1;32mC:\\Python310\\lib\\site-packages\\pandas\\io\\common.py:718\u001B[0m, in \u001B[0;36mget_handle\u001B[1;34m(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)\u001B[0m\n\u001B[0;32m    715\u001B[0m     codecs\u001B[38;5;241m.\u001B[39mlookup_error(errors)\n\u001B[0;32m    717\u001B[0m \u001B[38;5;66;03m# open URLs\u001B[39;00m\n\u001B[1;32m--> 718\u001B[0m ioargs \u001B[38;5;241m=\u001B[39m \u001B[43m_get_filepath_or_buffer\u001B[49m\u001B[43m(\u001B[49m\n\u001B[0;32m    719\u001B[0m \u001B[43m    \u001B[49m\u001B[43mpath_or_buf\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m    720\u001B[0m \u001B[43m    \u001B[49m\u001B[43mencoding\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mencoding\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m    721\u001B[0m \u001B[43m    \u001B[49m\u001B[43mcompression\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mcompression\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m    722\u001B[0m \u001B[43m    \u001B[49m\u001B[43mmode\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mmode\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m    723\u001B[0m \u001B[43m    \u001B[49m\u001B[43mstorage_options\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mstorage_options\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m    724\u001B[0m \u001B[43m\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    726\u001B[0m handle \u001B[38;5;241m=\u001B[39m ioargs\u001B[38;5;241m.\u001B[39mfilepath_or_buffer\n\u001B[0;32m    727\u001B[0m handles: \u001B[38;5;28mlist\u001B[39m[BaseBuffer]\n",
      "File \u001B[1;32mC:\\Python310\\lib\\site-packages\\pandas\\io\\common.py:372\u001B[0m, in \u001B[0;36m_get_filepath_or_buffer\u001B[1;34m(filepath_or_buffer, encoding, compression, mode, storage_options)\u001B[0m\n\u001B[0;32m    370\u001B[0m \u001B[38;5;66;03m# assuming storage_options is to be interpreted as headers\u001B[39;00m\n\u001B[0;32m    371\u001B[0m req_info \u001B[38;5;241m=\u001B[39m urllib\u001B[38;5;241m.\u001B[39mrequest\u001B[38;5;241m.\u001B[39mRequest(filepath_or_buffer, headers\u001B[38;5;241m=\u001B[39mstorage_options)\n\u001B[1;32m--> 372\u001B[0m \u001B[38;5;28;01mwith\u001B[39;00m \u001B[43murlopen\u001B[49m\u001B[43m(\u001B[49m\u001B[43mreq_info\u001B[49m\u001B[43m)\u001B[49m \u001B[38;5;28;01mas\u001B[39;00m req:\n\u001B[0;32m    373\u001B[0m     content_encoding \u001B[38;5;241m=\u001B[39m req\u001B[38;5;241m.\u001B[39mheaders\u001B[38;5;241m.\u001B[39mget(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mContent-Encoding\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;28;01mNone\u001B[39;00m)\n\u001B[0;32m    374\u001B[0m     \u001B[38;5;28;01mif\u001B[39;00m content_encoding \u001B[38;5;241m==\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mgzip\u001B[39m\u001B[38;5;124m\"\u001B[39m:\n\u001B[0;32m    375\u001B[0m         \u001B[38;5;66;03m# Override compression based on Content-Encoding header\u001B[39;00m\n",
      "File \u001B[1;32mC:\\Python310\\lib\\site-packages\\pandas\\io\\common.py:274\u001B[0m, in \u001B[0;36murlopen\u001B[1;34m(*args, **kwargs)\u001B[0m\n\u001B[0;32m    268\u001B[0m \u001B[38;5;250m\u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[0;32m    269\u001B[0m \u001B[38;5;124;03mLazy-import wrapper for stdlib urlopen, as that imports a big chunk of\u001B[39;00m\n\u001B[0;32m    270\u001B[0m \u001B[38;5;124;03mthe stdlib.\u001B[39;00m\n\u001B[0;32m    271\u001B[0m \u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[0;32m    272\u001B[0m \u001B[38;5;28;01mimport\u001B[39;00m \u001B[38;5;21;01murllib\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mrequest\u001B[39;00m\n\u001B[1;32m--> 274\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m urllib\u001B[38;5;241m.\u001B[39mrequest\u001B[38;5;241m.\u001B[39murlopen(\u001B[38;5;241m*\u001B[39margs, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mkwargs)\n",
      "File \u001B[1;32mC:\\Python310\\lib\\urllib\\request.py:216\u001B[0m, in \u001B[0;36murlopen\u001B[1;34m(url, data, timeout, cafile, capath, cadefault, context)\u001B[0m\n\u001B[0;32m    214\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[0;32m    215\u001B[0m     opener \u001B[38;5;241m=\u001B[39m _opener\n\u001B[1;32m--> 216\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mopener\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mopen\u001B[49m\u001B[43m(\u001B[49m\u001B[43murl\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mdata\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mtimeout\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32mC:\\Python310\\lib\\urllib\\request.py:525\u001B[0m, in \u001B[0;36mOpenerDirector.open\u001B[1;34m(self, fullurl, data, timeout)\u001B[0m\n\u001B[0;32m    523\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m processor \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mprocess_response\u001B[38;5;241m.\u001B[39mget(protocol, []):\n\u001B[0;32m    524\u001B[0m     meth \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mgetattr\u001B[39m(processor, meth_name)\n\u001B[1;32m--> 525\u001B[0m     response \u001B[38;5;241m=\u001B[39m \u001B[43mmeth\u001B[49m\u001B[43m(\u001B[49m\u001B[43mreq\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mresponse\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    527\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m response\n",
      "File \u001B[1;32mC:\\Python310\\lib\\urllib\\request.py:634\u001B[0m, in \u001B[0;36mHTTPErrorProcessor.http_response\u001B[1;34m(self, request, response)\u001B[0m\n\u001B[0;32m    631\u001B[0m \u001B[38;5;66;03m# According to RFC 2616, \"2xx\" code indicates that the client's\u001B[39;00m\n\u001B[0;32m    632\u001B[0m \u001B[38;5;66;03m# request was successfully received, understood, and accepted.\u001B[39;00m\n\u001B[0;32m    633\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m (\u001B[38;5;241m200\u001B[39m \u001B[38;5;241m<\u001B[39m\u001B[38;5;241m=\u001B[39m code \u001B[38;5;241m<\u001B[39m \u001B[38;5;241m300\u001B[39m):\n\u001B[1;32m--> 634\u001B[0m     response \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mparent\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43merror\u001B[49m\u001B[43m(\u001B[49m\n\u001B[0;32m    635\u001B[0m \u001B[43m        \u001B[49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43mhttp\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mrequest\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mresponse\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mcode\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mmsg\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mhdrs\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    637\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m response\n",
      "File \u001B[1;32mC:\\Python310\\lib\\urllib\\request.py:563\u001B[0m, in \u001B[0;36mOpenerDirector.error\u001B[1;34m(self, proto, *args)\u001B[0m\n\u001B[0;32m    561\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m http_err:\n\u001B[0;32m    562\u001B[0m     args \u001B[38;5;241m=\u001B[39m (\u001B[38;5;28mdict\u001B[39m, \u001B[38;5;124m'\u001B[39m\u001B[38;5;124mdefault\u001B[39m\u001B[38;5;124m'\u001B[39m, \u001B[38;5;124m'\u001B[39m\u001B[38;5;124mhttp_error_default\u001B[39m\u001B[38;5;124m'\u001B[39m) \u001B[38;5;241m+\u001B[39m orig_args\n\u001B[1;32m--> 563\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_call_chain\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43margs\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32mC:\\Python310\\lib\\urllib\\request.py:496\u001B[0m, in \u001B[0;36mOpenerDirector._call_chain\u001B[1;34m(self, chain, kind, meth_name, *args)\u001B[0m\n\u001B[0;32m    494\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m handler \u001B[38;5;129;01min\u001B[39;00m handlers:\n\u001B[0;32m    495\u001B[0m     func \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mgetattr\u001B[39m(handler, meth_name)\n\u001B[1;32m--> 496\u001B[0m     result \u001B[38;5;241m=\u001B[39m \u001B[43mfunc\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43margs\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    497\u001B[0m     \u001B[38;5;28;01mif\u001B[39;00m result \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[0;32m    498\u001B[0m         \u001B[38;5;28;01mreturn\u001B[39;00m result\n",
      "File \u001B[1;32mC:\\Python310\\lib\\urllib\\request.py:643\u001B[0m, in \u001B[0;36mHTTPDefaultErrorHandler.http_error_default\u001B[1;34m(self, req, fp, code, msg, hdrs)\u001B[0m\n\u001B[0;32m    642\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mhttp_error_default\u001B[39m(\u001B[38;5;28mself\u001B[39m, req, fp, code, msg, hdrs):\n\u001B[1;32m--> 643\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m HTTPError(req\u001B[38;5;241m.\u001B[39mfull_url, code, msg, hdrs, fp)\n",
      "\u001B[1;31mHTTPError\u001B[0m: HTTP Error 404: Not Found"
     ]
    }
   ],
   "source": [
    "# 设置最多显示10行\n",
    "pd.set_option('display.max_rows', 10)\n",
    "# 禁用科学计数法\n",
    "pd.set_option('display.float_format', lambda x: '%.2f' % x)\n",
    "# 防止SSL报错\n",
    "ssl._create_default_https_context = ssl._create_unverified_context\n",
    "# Costco 股价数据的网址\n",
    "url = 'https://finance.yahoo.com/quote/COST/history?p=COST&guccounter=1'\n",
    "#读取网页数据\n",
    "dfs = pd.read_html(url)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2023-12-18T21:28:22.279130Z",
     "end_time": "2023-12-18T21:28:22.295134Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
